/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameClass;

import Game.ShootBalloon;
import javax.microedition.lcdui.*;

/**
 *
 * @author THINH
 */
public class MainMenuScreen extends Canvas{
    
    private ShootBalloon ownmidlet;
    private  Image imutable = null;
    private Image mutable = null;
    private Image newGame = null;
    private Image settings = null;
    private Image exit = null;
    private int index =0;
    private static final int MAX_INDEX = 2;
    public MainMenuScreen(ShootBalloon midlet)
    {
        //Init menu
        ownmidlet = midlet;
        this.setFullScreenMode(true);
        try{
            imutable = Image.createImage("/resource/screen/MainMenuScreen.png");
            newGame = Image.createImage("/resource/screen/MainMenuNewGame.png");
            settings = Image.createImage("/resource/screen/MainMenuSettings.png");
            exit = Image.createImage("/resource/screen/MainMenuExit.png");
        }
        catch(Exception e)
        {
            
        }
    }
    
    public void paint(Graphics g)
    {
        //update image
        switch(index){
            case 0:
                mutable = newGame;
                break;
            case 1:
                mutable = settings;
                break;
            case 2:
                mutable = exit;
                break;
        }
        
        g.drawImage(imutable, 0, 0, 0);
        if(mutable!=null){
           g.drawImage(mutable,0,0,0);
        }
        
    }
    
    public void keyPressed(int keyCode)
    {
        
        int code = getGameAction(keyCode);
        if(code==UP){            
            if(--index<0){
            index = this.MAX_INDEX;
            }
            
        }
        
        if(code==DOWN){
            if(++index>this.MAX_INDEX){
            index = 0;
             
            }
        }
        
        if(code == FIRE){
            switch(index){
                case 0:
                    ownmidlet.setCurrent(ownmidlet.getPlayingScreen());
                    break;
                case 1:
                    ownmidlet.setCurrent(ownmidlet.getSettingScreen());
                    break;
                case 2:
                    ownmidlet.exitMIDlet();
                    break;
            }
        }
        repaint();
    }
    
}
